<?php

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

Route::namespace('Api')->middleware('mini_type.check')->group(function () {
    // 登录
    Route::post('authorizations/login', 'AuthorizationsController@store')
        ->name('authorizations.store');
    // 刷新token
    Route::put('authorizations/current', 'AuthorizationsController@update')
        ->name('authorizations.update');
    // 删除token
    Route::delete('authorizations/current', 'AuthorizationsController@destroy')
        ->name('authorizations.destroy');

    // 登录页
    Route::get('config', 'ConfigController@index')->name('config.index');

    // 获取首页模块
    Route::get('special/module', 'SpecialController@module')->name('special.module');
    Route::get('special/bottom_tab', 'SpecialController@bottomTab')->name('special.bottom_tab');

    // 首页
    Route::get('article/hot', 'ArticleController@hot')->name('article.hot');
    Route::get('article/list', 'ArticleController@list')->name('article.list');
    Route::get('article/detail', 'ArticleController@detail')->name('article.detail');
    Route::post('article/relay', 'ArticleController@relay')->name('article.relay');
    Route::get('article/tags', 'ArticleController@tags')->name('article.tags');

    // 图片上传
    Route::post('images', 'UploadController@upload');
    Route::post('imagesW', 'UploadController@uploadW');
    Route::post('imagesU', 'UploadController@uploadU');
    // //热门帖子
    Route::get('topic/hot', 'TopicController@hot');
    //帖子详情
    Route::get('topic/detail', 'TopicController@detail');
    //帖子标签
    Route::get('topic/tags', 'TopicController@tags')->name('topic.tags');

    Route::post('topic/relay', 'TopicController@relay')->name('article.relay');
    // Route::get('topic/list', 'TopicController@list');
    // Route::get('message/list','MessageController@list');
    // Route::get('topic/detail','TopicController@detail');

    Route::get('vip/list', 'VipController@list')->name('vip.list');

    Route::post('member/get_phone', 'MemberController@getPhone')
        ->name('member.get_phone');

    Route::prefix('common')->name('common.')->group(function () {
        //获取配置
        Route::get('config', 'ConfigController@config')->name('config');
        //评论通用语
        Route::get('quick_comment', 'ConfigController@quickComment')->name('quick_comment');
        //发送短信
        Route::post('send_sms', 'SendSmsController@send')->name('send_sms');
        //
        Route::get('msg_template', 'ConfigController@templateInfo')->name('active_template_info');

        // 主页导航
        Route::get('main_nav', 'CommonController@indexNav')->name('mani_nav');
        // 小程序导航
        Route::get('mini_app_nav', 'CommonController@miniAppNav')->name('mini_app_nav');
    });

    // 支付回调
    Route::prefix('wechat_notify')->name('wechat_notify.')->group(function () {
        Route::any('vip/pay/sn/{sn}', 'VipController@paidNotify')->name('vip_pay');
        Route::any('vip/refund/sn/{sn}', 'VipController@refundNotify')->name('vip_refund');

        Route::any('course/pay/sn/{sn}', 'CourController@paidNotify')->name('course_pay');
        Route::any('course/refund/sn/{sn}', 'CourController@refundNotify')->name('course_refund');
    });

    //中医经典
    Route::prefix('tcm')->name('tcm.')->group(function () {
        Route::get('main_nav', 'TcmController@main_nav')->name('main_nav');
        Route::get('tcm_detail', 'TcmController@tcm_detail')->middleware('need_vip:health')->name('tcm_detail');

        Route::get('tcm_food_attr', 'TcmController@tcm_food_attr')->name('tcm_food_attr');
        Route::get('tcm_food_list', 'TcmController@tcm_food_list')->name('tcm_food_list');

        Route::get('tcm_medicine_attr', 'TcmController@tcm_medicine_attr')->name('tcm_medicine_attr');
        Route::get('tcm_medicine_list', 'TcmController@tcm_medicine_list')->name('tcm_medicine_list');

        Route::get('tcm_doctor_firstLetter', 'TcmController@tcm_doctor_firstLetter')->name('tcm_doctor_firstLetter');
        Route::get('tcm_doctor_list', 'TcmController@tcm_doctor_list')->name('tcm_doctor_list');

        Route::get('tcm_case_list', 'TcmController@tcm_case_list')->name('tcm_case_list');

        Route::get('tcm_dongqipoint_list', 'TcmController@tcm_dongqipoint_list')->name('tcm_dongqipoint_list');

        Route::get('tcm_medicineddiet_attr', 'TcmController@tcm_medicineddiet_attr')->name('tcm_medicineddiet_attr');
        Route::get('tcm_medicineddiet_list', 'TcmController@tcm_medicineddiet_list')->name('tcm_medicineddiet_list');

        Route::get('tcm_drug_attr', 'TcmController@tcm_drug_attr')->name('tcm_drug_attr');
        Route::get('tcm_drug_list', 'TcmController@tcm_drug_list')->name('tcm_drug_list');

        Route::get('tcm_prescription_attr', 'TcmController@tcm_prescription_attr')->name('tcm_prescription_attr');
        Route::get('tcm_prescription_list', 'TcmController@tcm_prescription_list')->name('tcm_prescription_list');

        Route::get('tcm_tea_attr', 'TcmController@tcm_tea_attr')->name('tcm_tea_attr');
        Route::get('tcm_tea_list', 'TcmController@tcm_tea_list')->name('tcm_tea_list');

        Route::get('aroma/list', 'TcmController@tcm_aroma_list')->name('aroma.list');
        Route::get('aroma/condition', 'TcmController@tcm_aroma_condition')->name('aroma.condition');
    });

    Route::get('news/tags/{type}', 'NewTagsController@list')->name('news.tags');

    Route::prefix('member')->as('member.')->group(function () {
        Route::get('info', 'MemberInfoController@info')->name('content.info');
        Route::get('content/article', 'MemberInfoController@article')->name('content.article');
        Route::get('content/topic', 'MemberInfoController@topic')->name('content.topic');
        Route::get('content/collect', 'MemberInfoController@collect')->name('content.collect');
        Route::get('content/comment', 'MemberInfoController@comment')->name('content.comment');

        Route::get('follow/list', 'MemberFollowController@followList')->name('follow.list');
        Route::get('fans', 'MemberFollowController@fans')->name('fans');
    });

    Route::prefix('course')->as('course.')->group(function (){
        Route::get('list', 'CourController@list')->name('list');
        Route::get('details/{id}', 'CourController@details')->name('details');
    });

    // 登录后可以访问的接口
    Route::middleware('jwt.user')->group(function () {
        // 当前登录用户信息
        Route::get('member', 'MemberController@me')
            ->name('member.show');
        // 编辑登录用户信息
        Route::post('member/update', 'MemberController@update')
            ->name('member.update');
        Route::get('member/comments', 'MemberController@commentIndex')
            ->name('member.comments');
        Route::get('member/article', 'MemberController@articleIndex')
            ->name('member.article');
        Route::post('member/article/publish', 'MemberController@articleStore')
            ->name('member.article.publish');
        Route::post('member/bind_phone', 'MemberController@bindPhone')
            ->name('member.bind_phone');
        Route::get('member/collect/list', 'MemberCollectController@list')
            ->name('member.collect.list');
        Route::post('member/collect/cancel/{id}', 'MemberCollectController@cancel')
            ->name('member.collect.cancel');

        Route::post('member/follow', 'MemberFollowController@follow')
            ->name('member.follow');

        Route::post('member/vip_equity', 'MemberController@vipEquity')
            ->name('member.vip_equity');

        // 发布帖子
        Route::post('topic/publish', 'TopicController@publish');
        // 我的帖子(通过，审核中，未通过)
        Route::get('topic/list', 'TopicController@list');
        // 帖子删除
        Route::get('topic/delete', 'TopicController@delete');
        Route::post('topic/set_hot', 'TopicController@setHot')->name('topic.set_hot');
        //消息列表
        Route::get('message/list', 'MessageController@list');


        // 点赞(取消点赞)帖子
        Route::post('topic/favor', 'TopicController@favor')->name('topic.favor');
        Route::post('topic/disfavor', 'TopicController@disfavor')->name('topic.disfavor');
        // 评论帖子
        Route::post('topic/comment', 'TopicCommentController@comment')->name('topic.comment');
        Route::post('topic/comment/favor', 'TopicCommentController@favor')->name('topic.comment.favor');
        Route::post('topic/comment/disfavor', 'TopicCommentController@disfavor')->name('topic.comment.favor');

        // 点赞(取消点赞)文章
        Route::post('article/favor', 'ArticleController@favor')->name('article.favor');
        Route::post('article/disfavor', 'ArticleController@disfavor')->name('article.disfavor');
        // 文章删除
        Route::get('article/delete', 'ArticleController@delete')->name('article.delete');
        Route::post('article/set_hot', 'ArticleController@setHot')->name('article.set_hot');
        // 评论文章
        Route::post('article/comment', 'ArticleCommentController@comment')->name('article.comment');
        Route::post('article/comment/favor', 'ArticleCommentController@favor')->name('article.comment.favor');
        Route::post('article/comment/disfavor', 'ArticleCommentController@disfavor')->name('article.comment.favor');

        //积分相关
        Route::prefix('member/integral')->name('member.integral.')->group(function () {
            Route::get('/', 'IntegralController@index')->name('index');
            Route::get('/logs', 'IntegralController@logs')->name('logs');
            Route::post('/exchange', 'IntegralController@exchange')->name('exchange');
            Route::get('/info', 'IntegralController@info')->name('info');

            Route::get('/exchange/vip/info', 'IntegralController@exchangeVip')->name('exchange.vip.info');
            Route::post('/exchange/vip', 'IntegralController@exchangeVip')->name('exchange.vip');
        });

        //签到
        Route::prefix('member/sign')->name('member.sign.')->group(function () {
            Route::get('/', 'SignController@index')->name('index');
            Route::get('/sign_date_log', 'SignController@signDateLog')->name('sign_date_log');
        });

        //观看广告视频后回调
        Route::post('adv_video/callback', 'AdvVideoCallbackController@store')->name('adv_video.callback');

        // 创建vip支付订单
        Route::post('vip/unifiedOrder/vId/{vId}', 'VipController@unifiedOrder')->name('vip.unifiedOrder');

        // 留言相关
        Route::prefix('msg_board')->name('msg_board.')->group(function () {
            Route::get('list', 'MsgBoardController@list')->name('list');
            Route::post('store', 'MsgBoardController@store')->name('store');
        });

        // 自定义表单
        Route::prefix('diy_form')->name('diy_form.')->group(function () {
            Route::get('info/{id}', 'DiyFormController@info')->name('info')->where(['id' => '\d+']);
            Route::post('submit', 'DiyFormController@submit')->name('submit');
            Route::get('submit/history', 'DiyFormController@submitList')->name('submit_history_list');
            Route::get('submit/history/info/{id}', 'DiyFormController@submitInfo')->name('submit_history_info')->where(['id' => '\d+']);
        });

        // 审核中心
        Route::prefix('examine_center')->name('examine_center.center.')->group(function () {
            Route::prefix('topic')->name('topic.')->group(function () {
                Route::get('list', 'ExamineCenterController@topic')->name('list');
                Route::post('examine', 'ExamineCenterController@topicExamine')->name('examine');
                Route::post('set_hot/{id}', 'ExamineCenterController@topicSetHot')->name('set_hot')->where(['id' => '\d+']);
                Route::post('delete/{id}', 'ExamineCenterController@topicDelete')->name('delete')->where(['id' => '\d+']);
            });

            Route::prefix('comment')->name('comment.')->group(function () {
                Route::get('list', 'ExamineCenterController@comment')->name('list');
                Route::post('examine', 'ExamineCenterController@commentExamine')->name('examine');
                Route::post('delete', 'ExamineCenterController@commentDelete')->name('delete');
            });

            Route::prefix('msg_board')->name('msg_board.')->group(function () {
                Route::get('list', 'ExamineCenterController@msgBoard')->name('list');
                Route::post('reply', 'ExamineCenterController@msgBoardReply')->name('reply');
            });
        });

        // 课程
        Route::prefix('course')->as('course.')->group(function (){
            Route::post('collect/{id}', 'CourController@collect')->name('collect');
            Route::post('comment', 'CourController@comment')->name('comment');
            Route::get('source', 'CourController@source')->name('source');
            Route::post('watch_report', 'CourController@watchReport')->name('watch_report');
            Route::post('unifiedOrder', 'CourController@unifiedOrder')->name('unifiedOrder');
            Route::get('member/order', 'CourController@memberOrder')->name('member.order');
            Route::get('member/collect', 'CourController@collectList')->name('member.collect.list');
        });

        Route::prefix('tcm')->name('tcm.')->middleware('need_vip:health')->group(function () {
            // 书籍
            Route::prefix('book')->name('book.')->group(function (){
                Route::get('shelf', 'TcmBookController@collectList')->name('collect_list');
                Route::post('collect/{id}', 'TcmBookController@collect')->name('collect')->where(['id' => '\d+']);
                Route::post('batch_un_collect', 'TcmBookController@batchUnCollect')->name('collect');
                Route::get('list','TcmBookController@bookList')->name('list');
                Route::get('details','TcmBookController@bookDetails')->name('details');
                Route::get('chapter_details','TcmBookController@bookChapterDetails')->name('chapter_details');
                Route::get('search','TcmBookController@search')->name('search');
                Route::get('chapters_search','TcmBookController@chaptersSearch')->name('chapters_search');
            });
        });
    });
});
